/*
day469 
2020.12.9 
*/

#include<iostream>
#include<vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};


class Solution {
public:
    int maxAncestorDiff(TreeNode* root) {
		int max_dif=0;
		vector<int> vec;
		help(root,vec,max_dif);
		return max_dif;
    }
    
    void help(TreeNode *root,vector<int> &vec,int &max_dif)
	{
		if(!root) return ;
		for(int i=0;i<vec.size();++i)
		{
			max_dif=max(max_dif,abs(root->val-vec[i]));
		}
		
		vec.push_back(root->val);
		
		help(root->left,vec,max_dif);
		help(root->right,vec,max_dif);
		
		vec.pop_back();
	} 
};

int main()
{
	return 0;
 } 
